//
//  MLWLTPlayerControlView.m
//  KITCHEN_STORIES
//
//  Created by 孟令通 on 16/6/17.
//  Copyright © 2016年 MLW. All rights reserved.
//

#import "MLWLTPlayerControlView.h"

@implementation MLWLTPlayerControlView

- (void)dealloc
{
    
    [_topBackView release];
    [_playBackBtn release];
    [_bottomBackView release];
    [_playBtn release];
    [_currentTimeLabel release];
    [_fullScreenBtn release];
    [_playerProgressView release];
    [_totalTimeLabel release];
    [_playerSlider release];
    [_activityIndicator release];
    
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        // 初始化顶部遮罩层
        self.topBackView = [[UIView alloc] init];
        self.topBackView.backgroundColor = [UIColor colorWithRed:0.04 green:0.04 blue:0.04 alpha:0.40];
        [self addSubview:_topBackView];
        [_topBackView release];
        
        // 初始化返回按钮
        self.playBackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.playBackBtn setImage:[UIImage imageNamed:@"tipsPlayerBack"] forState:UIControlStateNormal];
        [self.topBackView addSubview:_playBackBtn];
        
        // 初始化底部遮罩层
        self.bottomBackView = [[UIView alloc] init];
        self.bottomBackView.backgroundColor = [UIColor colorWithRed:0.04 green:0.04 blue:0.04 alpha:0.40];
        [self addSubview:_bottomBackView];
        [_bottomBackView release];
        
        // 播放按钮
        self.playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.playBtn setImage:[UIImage imageNamed:@"tipsPlayerPause"] forState:UIControlStateNormal];
        [self.bottomBackView addSubview:_playBtn];
        
        // 初始化当前时间Label
        self.currentTimeLabel = [[UILabel alloc] init];
        [self.currentTimeLabel setFont:[UIFont systemFontOfSize:14]];
        self.currentTimeLabel.textColor = [UIColor colorWithRed:0.83 green:0.83 blue:0.83 alpha:1.00];
        [self.bottomBackView addSubview:_currentTimeLabel];
        [_currentTimeLabel release];
        
        // 初始化全屏按钮
        self.fullScreenBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.fullScreenBtn setImage:[UIImage imageNamed:@"tipsPlayerFullScreen"] forState:UIControlStateNormal];
        [self.bottomBackView addSubview:_fullScreenBtn];
        
        // 初始化播放器进度条
        self.playerProgressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
        [self.bottomBackView addSubview:_playerProgressView];
        [_playerProgressView release];
        
        // 初始化总时长
        self.totalTimeLabel = [[UILabel alloc] init];
        [self.totalTimeLabel setFont:[UIFont systemFontOfSize:14]];
        self.totalTimeLabel.textColor = [UIColor colorWithRed:0.83 green:0.83 blue:0.83 alpha:1.00];
        [self.bottomBackView addSubview:_totalTimeLabel];
        [_totalTimeLabel release];
        
        // 初始化进度滑条
        self.playerSlider = [[UISlider alloc] init];
        [self.playerSlider setThumbImage:[UIImage imageNamed:@"circle"] forState:UIControlStateNormal];
        [self.bottomBackView addSubview:_playerSlider];
        [_playerSlider release];
        
        // 初始化加载等待图标
        self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
        [self addSubview:_activityIndicator];
        [_activityIndicator release];
        
        
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    // 布局顶部遮罩层
    [self.topBackView makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self).offset(0);
        
        make.left.equalTo(self).offset(0);
        
        make.right.equalTo(self).offset(0);
        
        make.height.equalTo(40);
        
    }];
    
    // 布局返回按钮
    [self.playBackBtn makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self).offset(10);
        
        make.left.equalTo(self).offset(5);
        
        make.height.equalTo(20);
        
        make.width.equalTo(20);
        
    }];
    
    // 布局底部遮罩层
    [self.bottomBackView makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self).offset(0);
        
        make.left.equalTo(self).offset(0);
        
        make.right.equalTo(self).offset(0);
        
        make.height.equalTo(40);
        
    }];
    
    // 布局播放按钮
    [self.playBtn makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.bottomBackView.top).equalTo(10);
        
        make.left.equalTo(self.bottomBackView.left).equalTo(10);
        
        make.height.equalTo(20);
        
        make.width.equalTo(20);
        
    }];
    
    // 布局当前时间Label
    [self.currentTimeLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.playBtn.right).offset(10);
        
        make.top.equalTo(self.bottomBackView.top).offset(5);
        
        make.width.equalTo(40);
        
        make.bottom.equalTo(self.bottomBackView.bottom).offset(-5);
        
    }];
    self.currentTimeLabel.text = @"00:00";
    
    // 布局全屏按钮
    [self.fullScreenBtn makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self.bottomBackView.right).offset(-10);
        
        make.top.equalTo(self.bottomBackView.top).offset(10);
        
        make.bottom.equalTo(self.bottomBackView.bottom).offset(-10);
        
        make.width.equalTo(20);
        
    }];
    
    // 布局总时长
    [self.totalTimeLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.bottomBackView.top).offset(5);
        
        make.right.equalTo(self.fullScreenBtn.left).offset(-10);
        
        make.bottom.equalTo(self.bottomBackView.bottom).offset(-5);
        
        make.width.equalTo(40);
        
    }];
    self.totalTimeLabel.text = @"00:00";
    
    // 布局进度条
    [self.playerProgressView makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.bottomBackView.top).offset(20);
        
        make.left.equalTo(self.currentTimeLabel.right).offset(10);
        
        make.right.equalTo(self.totalTimeLabel.left).offset(-10);
        
        make.height.equalTo(1);
        
    }];
    self.playerProgressView.progressTintColor = [UIColor colorWithRed:0.38 green:0.69 blue:0.89 alpha:1.00];

    
    // 布局进度滑条
    [self.playerSlider makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.bottomBackView.top).offset(20);
        
        make.left.equalTo(self.currentTimeLabel.right).offset(10);
        
        make.right.equalTo(self.totalTimeLabel.left).offset(-10);
        
        make.height.equalTo(1);
        
    }];
    self.playerSlider.maximumTrackTintColor = [UIColor colorWithRed:0.83 green:0.83 blue:0.83 alpha:0.00];
    self.playerSlider.minimumTrackTintColor = [UIColor colorWithRed:0.99 green:0.75 blue:0.18 alpha:1.00];
    
//    // 布局加载等待图标
//    [self.activityIndicator makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.left.equalTo(self).offset(ScreenWidth / 2.0);
//        
//        make.top.equalTo(self).offset(ScreenHeight / 2.0);
//        
//        make.width.equalTo(20);
//        
//        make.height.equalTo(20);
//        
//    }];
    
}

-(void)showControlView
{
    self.topBackView.alpha = 1.0f;
    
    self.bottomBackView.alpha = 1.0f;
}

-(void)hiddenControlView
{
    self.topBackView.alpha = 0;
    
    self.bottomBackView.alpha = 0;
}


@end
